<template>
  <div class="app-container">
    <el-card class="mar_bottom">
      <el-search-form label-width="90px" @search="onSearch" @reset="onReset">
        <el-form-item>
          <el-select
            size="small"
            style="width: 100px; margin-right: -2px"
            v-model="timeType"
            placeholder="请选择"
          >
            <el-option label="创建时间" value="createDate"></el-option>
            <el-option label="订单时间" value="orderTime"></el-option>
          </el-select>
          <el-date-picker
            size="small"
            v-model="searchBody.timeRange"
            style="width: 350px"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          ></el-date-picker>
        </el-form-item>


        <el-form-item label="订单ID">
          <el-input
            clearable
            size="small"
            v-model="searchBody.id"
            class="el-input__small"
          ></el-input>
        </el-form-item>
        <el-form-item label="业主手机号">
          <el-input
            clearable
            size="small"
            v-model="searchBody.phone"
            class="el-input__small"
          ></el-input>
        </el-form-item>
        <el-form-item label="注册人账号">
          <el-input
            clearable
            size="small"
            v-model="searchBody.userPhone"
            class="el-input__small"
          ></el-input>
        </el-form-item>
        <el-form-item label="注册人上级账号">
          <el-input
            clearable
            size="small"
            v-model="searchBody.pUserPhone"
            class="el-input__small"
          ></el-input>
        </el-form-item>
        <el-form-item label="审核日期">
          <el-date-picker
            v-model="searchBody.audiDate"
            type="date"
            placeholder="选择日期"
            @change="handleChangeAudiDate"
          >
          </el-date-picker>
        </el-form-item>
      </el-search-form>
    </el-card>

    <el-card>
      <el-tabs
        style="margin-top: 15px"
        v-model="searchBody.audiStatus"
        @tab-click="getData"
      >
        <el-tab-pane label="全部" name="0"></el-tab-pane>
        <el-tab-pane label="待审核" name="1"></el-tab-pane>
        <el-tab-pane label="有效" name="5"></el-tab-pane>
        <el-tab-pane label="黄金" name="11"></el-tab-pane>
        <el-tab-pane label="白金" name="12"></el-tab-pane>
        <el-tab-pane label="钻石" name="13"></el-tab-pane>

      </el-tabs>

      <el-pagination
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="pageSizeOpts"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      >
      </el-pagination>
      <div class="have-pagination-container">
        <el-table v-loading="loading.list" :data="list">
          <el-table-column
            label="线索ID"
            prop="id"
            align="center"
            width="50"
          ></el-table-column>
          <el-table-column
            label="创建时间"
            prop="createDate"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="业主"
            prop="name"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="业主手机号"
            prop="phone"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="注册人手机号"
            prop="zhucePhone"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="城市"
            prop="cityValue"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="地址"
            prop="address"
            align="center"
            width="360"
          ></el-table-column>
          <el-table-column
            label="面积"
            prop="mianji"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="喜欢风格"
            prop="xihuanfenggeValue"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="订单价格"
            prop="orderPrice"
            align="center"
            width="160"
          ></el-table-column>
          <el-table-column
            label="是否量房"
            prop="isLiangfang"
            align="center"
            width="160"
            :filter-method="filterTag"
            filter-placement="bottom-end"
          >
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.isLiangfang === '1' ? 'success' : 'danger'"
                disable-transitions>{{scope.row.isLiangfangValue}}</el-tag>
            </template>

          </el-table-column>
          <el-table-column
            label="是否电话"
            prop="isDadianhua"
            align="center"
            width="160"
            :filter-method="filterTag"
            filter-placement="bottom-end"
          >
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.isDadianhua === '1' ? 'success' : 'danger'"
                disable-transitions>{{scope.row.isDadianhuaValue}}</el-tag>
            </template>

          </el-table-column>

          <el-table-column
            align="center"
            fixed="right"
            label="操作"
            width="100"
          >
            <template slot-scope="scope">
              <el-button
                type="primary"
                size="mini"
                @click="handleClick('selectShouyi', scope.row)"
                >收益</el-button>
              <el-button
                type="text"
                size="small"
                @click="handleClick('xiangqing', scope.row)"
              >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="pageSizeOpts"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      >
      </el-pagination>
    </el-card>
    <!-- 编辑业主信息 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="dialogTitle2"
      :visible.sync="editDialog"
      fullscreen
    >
      <el-form label-suffix=":" label-width="100px">
        <el-form-item label="业主">
          <el-input
            v-model="updateForm.name"
            class="el-input__medium"
          ></el-input>
          <el-radio-group style="margin-left: 15px" v-model="updateForm.sex">
            <el-radio label="1">男</el-radio>
            <el-radio label="2">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="电话">
          <el-input
            v-if="true"
            v-model="updateForm.phone"
            class="el-input__medium"
          ></el-input>
          <span v-else> {{ updateForm.phone }}</span>
        </el-form-item>
        <el-form-item label="区域">
          <el-cascader
            v-model="updateForm.addrCode"
            :options="areaOptions"
            :props="{
              label: 'name',
              value: 'code',
            }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="地址">
          <el-input
            v-model="updateForm.address"
            class="el-input__medium"
          ></el-input>
        </el-form-item>
        <el-form-item label="面积">
          <el-input class="el-input__small" v-model="updateForm.mianji">
            <template slot="append">m²</template>
          </el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            class="el-input__medium"
            type="textarea"
            v-model="updateForm.remark"
          ></el-input>
        </el-form-item>
        <el-form-item label="日志">
          <el-input
            class="el-input__medium"
            type="textarea"
            v-model="updateForm.logs"
          ></el-input>
        </el-form-item>
        <template v-if="handleType == 'update'">
          <el-form-item label="状态">
            <el-select v-model="updateForm.audiStatus" placeholder="请选择">
              <el-option
                v-for="(item, idx) in jsStatusOptions"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="房屋概况">
            <el-select v-model="updateForm.fangwugaikuan1" placeholder="请选择">
              <el-option
                v-for="(item, idx) in fw1Options"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
            <el-select v-model="updateForm.fangwugaikuan2" placeholder="请选择">
              <el-option
                v-for="(item, idx) in fw2Options"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="装修方式">
            <el-select
              v-model="updateForm.zhuangxiufangshi1"
              placeholder="请选择"
            >
              <el-option
                v-for="(item, idx) in zxfs1Options"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
            <el-select
              v-model="updateForm.zhuangxiufangshi2"
              placeholder="请选择"
            >
              <el-option
                v-for="(item, idx) in zxfs2Options"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
            <el-select
              v-model="updateForm.zhuangxiufangshi3"
              placeholder="请选择"
            >
              <el-option
                v-for="(item, idx) in zxfs3Options"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
            <el-select
              v-model="updateForm.zhuangxiufangshi4"
              placeholder="请选择"
            >
              <el-option
                v-for="(item, idx) in zxfs4Options"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="喜欢风格">
            <el-select v-model="updateForm.xihuanfengge" placeholder="请选择">
              <el-option
                v-for="(item, idx) in xhfgOptions"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="装修预算">
            <el-select
              v-model="updateForm.zhuangxiuyusuan"
              placeholder="请选择"
            >
              <el-option
                v-for="(item, idx) in zxysOptions"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="预约量房">
            <el-date-picker
              size="small"
              v-model="updateForm.yuyueliangfang"
              type="datetime"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="归属"> {{ updateForm.guishu }} </el-form-item>
          <el-form-item label="来源">
            {{ updateForm.resourceValue }}
          </el-form-item>
          <el-form-item label="订单日志">
            <el-table border :data="orderRiZhi">
              <el-table-column
                width="160"
                label="记录时间"
                prop="systemName"
                align="center"
              ></el-table-column>
              <el-table-column
                width="160"
                label="操作员"
                prop="moduleName"
                align="center"
              ></el-table-column>
              <el-table-column
                label="标题"
                prop="moduleValue"
                align="center"
              ></el-table-column>
              <el-table-column
                label="日记"
                prop="methodName"
                align="center"
              ></el-table-column>
            </el-table>
          </el-form-item>
        </template>
        <template v-else>
          <el-form-item label="营销类别">
            <el-select v-model="updateForm.marketingType" placeholder="请选择">
              <el-option label="正常" value="1"></el-option>
              <el-option label="删除" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="来源">
            <el-select v-model="updateForm.resouces" placeholder="请选择">
              <el-option
                v-for="(item, idx) in resourceOptions"
                :key="idx"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </template>
      </el-form>
      <div slot="footer">
        <el-button @click="editDialog = false">取 消</el-button>
        <el-button type="primary" @click="handleSure()">保 存</el-button>
      </div>
    </el-dialog>
    <!-- 查看详情信息 -->
    <XiangDiaZhizun ref="xiaDiaZhizunRef" @closeDiaFun="closeXiaDia"></XiangDiaZhizun>
    <!-- 接单/派单/订单/结算... -->
    <el-dialog
      :close-on-click-modal="false"
      :title="dialogTitle"
      :visible.sync="lookDialog"
      fullscreen
    >
      <div class="power_right">
        <el-button
          title="刷新"
          icon="el-icon-refresh-right"
          size="medium"
          circle
          @click="getData2"
        ></el-button>
        <el-dropdown :hide-on-click="false" trigger="click">
          <el-button
            style="margin-left: 10px"
            title="筛选列"
            icon="el-icon-menu"
            size="medium"
            circle
          ></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-for="(item, idx) in tableColumn2" :key="idx">
              <el-checkbox v-model="item.checked">{{ item.label }}</el-checkbox>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown trigger="click" @command="handleCommand">
          <el-button
            style="margin-left: 10px"
            title="导出"
            icon="el-icon-upload2"
            size="medium"
            circle
          ></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="csv">导出csv格式文件</el-dropdown-item>
            <el-dropdown-item command="xls">导出xls格式文件</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-table show-summary v-loading="loading.list2" :data="list">
        <el-table-column
          v-if="tableColumn2[0].checked"
          label="线索ID"
          prop="id"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[1].checked"
          label="订单GUID"
          prop="id"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[2].checked"
          label="线索UUID"
          prop="id"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[3].checked"
          label="线索姓名"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[4].checked"
          label="线索城市"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[5].checked"
          label="线索时间"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[6].checked"
          label="渠道主"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[7].checked"
          label="达人"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[8].checked"
          label="派单时间"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[9].checked"
          label="接单时间"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[10].checked"
          label="产生需求"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[11].checked"
          label="需求时间(订单)"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[12].checked"
          label="需求城市"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[13].checked"
          label="渠道主奖励"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[14].checked"
          label="达人奖励"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[15].checked"
          label="结算状态"
          prop="name"
          align="center"
        ></el-table-column>
        <el-table-column
          v-if="tableColumn2[16].checked"
          label="结算时间"
          prop="name"
          align="center"
        ></el-table-column>
      </el-table>
    </el-dialog>
    <!-- 派单弹窗 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="dialogTitle3"
      :visible.sync="paidanDialog"
      fullscreen
    >
      <el-form label-suffix=":">
        <el-form-item label="业主">{{ paidanData.yezhu }}</el-form-item>
        <el-form-item label="地址">{{ paidanData.address }}</el-form-item>
        <el-form-item label="已派单">
          <el-table :data="paidanData.yipaidan">
            <el-table-column
              label="商家"
              prop="jiazhuangPlatformName"
              align="center"
            ></el-table-column>
            <el-table-column
              label="派单时间"
              prop="paidanDate"
              align="center"
            ></el-table-column>
            <el-table-column
              label="操作员"
              prop="createUser"
              align="center"
            ></el-table-column>
            <el-table-column
              label="接单时间"
              prop="jiedanDate"
              align="center"
            ></el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="未派单">
          <el-table
            border
            :data="paidanData.weipaidan"
            @selection-change="onSelectionChange"
          >
            <el-table-column type="selection" width="50"></el-table-column>
            <el-table-column
              label="商家"
              prop="jiazhuangPlatformName"
              align="center"
            ></el-table-column>
            <el-table-column
              label="最后派单时间"
              prop="lastPaidanDate"
              align="center"
            ></el-table-column>
            <el-table-column
              label="最后接单时间"
              prop="lastJiedanDate"
              align="center"
            ></el-table-column>
            <el-table-column
              label="操作员"
              prop="createUser"
              align="center"
            ></el-table-column>
            <el-table-column
              label="标题"
              prop="title"
              align="center"
            ></el-table-column>
            <el-table-column
              label="日记"
              prop="logs"
              align="center"
            ></el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="paidanDialog = false">取 消</el-button>
        <el-button type="primary" @click="handleSure('paidan')"
          >派 单</el-button
        >
      </div>
    </el-dialog>

    <!-- 订单收益明细弹窗 -->
    <el-dialog
      :title="shouyiDialogTitle"
      :visible.sync="shouyiDialog"
      width="55%"
      :close-on-click-modal="false"
    >

      <!-- 二级节点value列表 -->
      <div class="have-pagination-container">
        <el-table border v-loading="loading.childList" :data="childList"  :row-class-name="shouyiTableRowClassName" :span-method="objectSpanMethod">
          <el-table-column prop="phone" label="电话（账号）"></el-table-column>
          <el-table-column prop="shouyi" label="收益"></el-table-column>
          <el-table-column prop="levelValue" label="等级"></el-table-column>
          <el-table-column prop="shouyiType" label="收益类型"></el-table-column>
          <el-table-column prop="canTixian" label="是否可提现"></el-table-column>
          <el-table-column prop="getShouyiDate" label="收益时间"></el-table-column>
<!--          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="handleClick('updateChild', scope.row)"
              >修改</el-button
              >
              <el-button
                type="text"
                size="small"
                @click="handleClick('removeChild', scope.row)"
              >删除</el-button
              >
            </template>
          </el-table-column>-->
        </el-table>
      </div>
      <div class="pagination-box">
        <el-pagination
          @current-change="handleCurrentChangeChild('childList', $event)"
          @size-change="handleSizeChangeChild('childList', $event)"
          :current-page.sync="childPageNo"
          :page-size="childPageSize"
          :page-sizes="pageSizeOpts"
          layout="total, sizes, prev, pager, next"
          :total="childTotalCount"
        >
        </el-pagination>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="shouyiDialog = false"
        >关 闭</el-button
        >
<!--        <el-button type="primary" @click="handleSure('updateValue')"
        >确 定</el-button
        >-->
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  paidanOrder,
  selectPaidanPageVo,
  selectRegionTree,
  sysDictbyMultiType,
  addNewOrder,
  editXiansuo,
  exportInData,
  exportOutData,
  selectAllJiaZhuangOrderPage,
  jiazhuangdingdanshenhe,
  selectShouyiPageByOrder, selectJiaOrderDetailVo,
} from "@/api/api.js";
import {sysDict_childList, sysDict_delete} from "@/api/dataDict";
import XiangDiaZhizun from "./xiangDiaZhizun.vue";
import XiangDiaShangwu from "@/views/tuiManage/xiangDiaShangwu";


const getDefaultForm = () => ({
  name: null,
  sex: null,
  phone: null,
  addrCode: null,
  address: null,
  mianji: null,
  resouces: null,
  remark: null,
  logs: null,
  marketingType: null,
});
const getDefaultSearchBody = () => ({
  timeRange: null,
  resource: null,
  phone: null,
  yezhu: null,
  orderNo: null,
  userIdList: null,
  id: null,
  audiStatus: "0",
  zhuchePhone:null,
});
export default {
  components: {
    XiangDiaZhizun,
  },
  data() {
    return {
      orderRiZhi: [],
      areaOptions: [],
      qdzOptions: [],
      resourceOptions: [],
      fw1Options: [],
      fw2Options: [],
      zxfs1Options: [],
      zxfs2Options: [],
      zxfs3Options: [],
      zxfs4Options: [],
      xhfgOptions: [],
      zxysOptions: [],
      jsStatusOptions: [],
      timeType: "createDate",
      searchType: "phone",
      dialogTitle: "",
      dialogTitle2: "",
      dialogTitle3: "",
      handleType: "",
      pageNo: 1,
      pageSize: 20,
      totalCount: 0,
      childPageNo: 1,
      childPageSize: 20,
      childTotalCount: 0,
      pageSizeOpts: [20, 50, 100, 300, 500],
      loading: {
        list: false,
        list2: false,
        childList: false,
      },
      list: [],
      paidanData: {},
      selectRow: [], // 选中行
      lookDialog: false,
      editDialog: false,
      paidanDialog: false,
      shouyiDialog: false,
      shouyiOrderId: 0,
      shouyiDialogTitle: "",
      updateForm: getDefaultForm(),
      searchBody: getDefaultSearchBody(),
      tableColumn: [
        {
          label: "线索ID",
          checked: true,
        },
        {
          label: "线索业主",
          checked: true,
        },
        {
          label: "线索手机",
          checked: true,
        },
        {
          label: "线索城市",
          checked: true,
        },
        {
          label: "派单",
          checked: true,
        },
        {
          label: "接单",
          checked: true,
        },
        {
          label: "订单",
          checked: true,
        },
        {
          label: "结算",
          checked: true,
        },
        {
          label: "标记",
          checked: true,
        },
        {
          label: "更新小计",
          checked: true,
        },
        {
          label: "来源",
          checked: true,
        }
       /* {
          label: "管理员/渠道主/达人",
          checked: true,
        },*/
        /*{
          label: "手机归属",
          checked: true,
        },
        {
          label: "线索时间",
          checked: true,
        },
        {
          label: "需求时间（订单）",
          checked: true,
        },
        {
          label: "更新时间",
          checked: true,
        },
        {
          label: "更新人",
          checked: true,
        },*/
      ],
      tableColumn2: [
        {
          label: "线索ID",
          checked: true,
        },
        {
          label: "订单GUID",
          checked: false,
        },
        {
          label: "线索UUID",
          checked: true,
        },
        {
          label: "线索姓名",
          checked: true,
        },
        {
          label: "线索城市",
          checked: true,
        },
        {
          label: "线索时间",
          checked: true,
        },
        {
          label: "渠道主",
          checked: true,
        },
        {
          label: "达人",
          checked: true,
        },
        {
          label: "派单时间",
          checked: true,
        },
        {
          label: "接单时间",
          checked: true,
        },
        {
          label: "产生需求",
          checked: true,
        },
        {
          label: "需求时间(订单)",
          checked: true,
        },
        {
          label: "需求城市",
          checked: true,
        },
        {
          label: "渠道主奖励",
          checked: true,
        },
        {
          label: "达人奖励",
          checked: true,
        },
        {
          label: "结算状态",
          checked: true,
        },
        {
          label: "结算时间",
          checked: true,
        },
      ],
      xiangData: {
        name: null,
      },
    };
  },
  created() {
    this.getData();
    //this.getQdzOptions();
    //this.getOptions();
  },
  methods: {

    closeXiaDia(val) {
      this.getData();
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        let nameSpan = this.getSpanNumber(this.childList, "phone");
        return {
          rowspan: nameSpan[rowIndex],
          colspan: 1,
        };
      }
    },
    getSpanNumber(data, prop) {
      //data要处理的数组，prop要合并的属性，比如name

      //数组的长度，有时候后台可能返回个null而不是[]
      let length = Array.isArray(data) ? data.length : 0;
      if (length > 0) {
        //用于标识位置
        let position = 0;
        //用于对比的数据
        let temp = data[0][prop];
        //要返回的结果
        let result = [1];
        //假设数据是AABCC，我们的目标就是返回20120
        for (let i = 1; i < length; i++) {
          if (data[i][prop] == temp) {
            //标识位置的数据加一
            result[position] += 1;
            //当前位置添0
            result[i] = 0;
          } else {
            //不相同时，修改标识位置，该位置设为1，修改对比值
            position = i;
            result[i] = 1;
            temp = data[i][prop];
          }
        }
        //返回结果
        return result;
      } else {
        return [0];
      }
    },
    shouyiTableRowClassName({row, rowIndex}){
      for(var i=0;i<this.childList.length;i++){
        var levelId = this.childList[i].levelId;
        if(levelId === 1){
          return 'huangjing-row';
        }else if(levelId === 2){
          return 'baijin-row';
        }else if(levelId === 3){
          return 'zuanshi-row';
        }
      }

    },
    onSearchTypeChange(key) {
      let val;
      for (let key2 of ["yezhu", "phone", "orderNo", "id"]) {
        val = this.searchBody[key2] || val;
      }
      this.searchBody = Object.assign(this.searchBody, {
        [key]: val,
      });
    },
    getData() {
      this.loading.list = true;
      const { timeRange, userIdList, ...rest } = this.searchBody;
      const [startTime, endTime] = timeRange || [null, null];
      /*const _userIdList = (userIdList || []).reduce((a, b) => {
        return Array.from(new Set(a.concat(b)));
      }, []);*/
      selectAllJiaZhuangOrderPage({
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        startTime: startTime,
        endTime: endTime,

        ...rest,
      }).then(({ result }) => {
        this.list = result.data;
        this.totalCount = result.totalCount;
        this.loading.list = false;
      });
    },
    getShouyiData() {
      this.loading.childList = true;
      selectShouyiPageByOrder({
        pageNo: this.childPageNo,
        pageSize: this.childPageSize,
        id: this.shouyiOrderId,
      })
        .then(({ result = {} }) => {
          this.childList = result.data;
          this.childTotalCount = result.totalCount;
          this.loading.childList = false;
        })
        .catch(() => {
          this.loading.childList = false;
        });
    },
    getData2() {},
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageNo = val;
      this.getData();
    },
    handleCurrentChangeChild(type, val) {
      switch (type) {
        case "list":
          this.pageNo = val;
          this.getData();
          break;
        case "childList":
          this.childPageNo = val;
          this.getShouyiData();
          break;
      }
    },
    handleSizeChangeChild(type, val) {
      switch (type) {
        case "list":
          this.pageSize = val;
          this.getData();
          break;
        case "childList":
          this.childPageSize = val;
          this.getShouyiData();
          break;
      }
    },
    handleSelectionChange(val) {
      this.selectIds = val.map((d) => d.id);
    },
    onSearch() {
      this.pageNo = 1;
      this.getData();
    },
    onReset() {
      this.pageNo = 1;
      this.searchBody = getDefaultSearchBody();
      this.getData();
    },
    handleClick(type, row, title) {
      this.handleType = type;
      switch (type) {
        case "look":
          this.dialogTitle = "订单ID:" + row.id + "-" + title;
          this.lookDialog = true;
          break;
        case "xiangqing":
          selectJiaOrderDetailVo({
            id: row.id,
          }).then((res) => {
            this.xiangData = res.result;
            this.$refs.xiaDiaZhizunRef.openDia(this.xiangData);
          });
          break;
        case "add":
          this.dialogTitle2 = "营销-添加";
          this.editDialog = true;
          this.updateForm = getDefaultForm();
          break;
        case "update":
          this.dialogTitle2 = "营销ID:" + row.id + "-编辑";
          selectXiansuoInfoVo({
            id: row.id,
          }).then((res) => {
            const { provinceCode, cityCode, areaCode, ...rest } = res.result;
            this.updateForm = Object.assign(rest, {
              addrCode: [provinceCode, cityCode, areaCode],
            });
            this.editDialog = true;
          });
          break;
        case "fenpai":
          break;
        case "exportOut":
          exportOutData().then((res) => {
            this.$message.success("导出成功");
          });
          break;
        case "paidan":
          this.dialogTitle3 = "订单ID:" + row.id + "-派单";
          selectPaidanPageVo({
            id: row.id,
          }).then((res) => {
            const paidanData = res.result || {};
            paidanData.orderId = row.id;
            this.paidanData = paidanData;
            this.paidanDialog = true;
          });
          break;
        case "shenhe":
          this.$confirm(`确认审核通过？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            jiazhuangdingdanshenhe({
              id: row.id,
            }).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break
        case "selectShouyi":
          this.shouyiDialogTitle = "收益明细 - 订单金额 ："+row.orderPrice;
          this.shouyiDialog = true;
          this.shouyiOrderId = row.id;
          this.getShouyiData();
          break;
        default:
          return;
      }
    },
    handleSure(type) {
      type = type || this.handleType;
      const { addrCode, ...rest } = this.updateForm;
      const [provinceCode, cityCode, areaCode] = addrCode;
      switch (type) {
        case "add":
          addNewOrder({
            provinceCode,
            cityCode,
            areaCode,
            ...rest,
          }).then((res) => {
            this.$message.success("保存成功");
          });
          break;
        case "update":
          editXiansuo({
            provinceCode,
            cityCode,
            areaCode,
            ...rest,
          }).then((res) => {
            this.$message.success("保存成功");
          });
          break;
        case "paidan":
          paidanOrder({
            orderId: this.paidanData.orderId,
            jiazhuangPlatformIdList: this.selectRow.map((d) => {
              return d.jiazhuangPlatformId;
            }),
          }).then((res) => {
            this.$message.success("派单成功");
            this.paidanDialog = false;
          });
          break;
        default:
          return;
      }
    },
    onSelectionChange(val) {
      this.selectRow = val;
    },
    handleCommand(command) {
      this.$message("click on item " + command);
    },
    uploadData(params) {
      const form = new FormData();
      form.append("file", params.file);
      const loading = this.$loading({
        lock: true,
        text: "正在导入...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      exportInData(form)
        .then((res) => {
          this.$message.success("导入成功");
          loading.close();
        })
        .catch(() => {
          loading.close();
        });
    },
    beforeUpload(file) {
      if (file.size > 1 * 1024 * 1024) {
        this.$message.warning("上传的文件大小不能超过1MB!");
        return false;
      }
    },
  },
};
</script>

<style>
.power_right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 30px;
  margin-bottom: 10px;
}

.block {
  display: flex;
  height: 70px;
}
.block_item {
  padding: 5px 30px;
  box-sizing: border-box;
  border-right: 1px solid #ddd;
  color: #5f5f5f;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.block_item:first-of-type {
  border-right: 0;
  align-self: flex-start;
}
.value {
  font-size: 24px;
  font-weight: bold;
}

.baijin-row {
  background: #fffbec;
}

.huangjing-row {
  background: #fff740;
}

.zuanshi-row {
  background: #95ffff;
}
</style>
